package com.xiyi.shouxin.utils;

import com.xiyi.shouxin.exception.CommonException;
import com.xiyi.shouxin.exception.ErrorCode;
import com.xiyi.shouxin.view.CommonModel;

//错误工具类
public class ExceptionUtil {

    public static CommonException Convert(Exception e) {
        if (e instanceof CommonException) {
            return (CommonException) e;
        }
        return new CommonException(ErrorCode.INTERNAL);
    }

    public static CommonModel GetCommonModel(Exception e) {
        CommonException err = Convert(e);
        return CommonModel.Fail(err.getErrorCode().getCode(), err.getErrorCode().getMsg(), null);
    }

}
